<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>QQ 登陆</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="app_static/js/main.js"></script>
  </head>
  
  <body>
  	<div>抢票系统登陆</div>
  	<img id="qqLogin" src="app_static/image/qqLogin.png" onclick="javascript:jumpQQ();">
  	<div style="display:none;" id="welcome">欢迎来到抢票系统！</div>
  	<a href="<%=request.getContextPath()%>/loginTest.htm">测试登陆入口</a>
  </body>
  <script>
  	 //qq登陆页面
  	 var qqUrl = 'https://graph.qq.com/oauth2.0';
  	//应用的APPID 
     var appID = "1111111111";
  	
  	 var redirectURI = "www.moana.com"; 
  	 function jumpQQ(){
  		 var path = qqUrl + '/authorize?';
  		var queryParams = ['client_id=' + appID, 
                           'redirect_uri=' + redirectURI, 
                           'scope=' + 'get_user_info'];
  		var query = queryParams.join("&");
  		var url = path + query;
  		window.location.href=url;
  	 }
  	 
  	 var accessToken ;
  	 //获取openId
  	 function callback(obj){
  		 var openId = obj.openId;
  		 var url = redirectURI + "/login.html"+"?access_token=" + accessToken + "&openid=" + openid+"appID="+appID;
  		 $('#qqLogin').hide();
  		 $('#welcome').show();
  		 document.location.href = url;
  	 }
  	 
  	 window.onload = function(){
  		 if(window.location.hash.length!=0){
  			 //获取access_token 
  			 var param = window.location.hash.substring(1);
  			 var map = toParamMap(param);
  			 var path = qqUrl + '/me?';
  			 accessToken = map.access_token;
             var queryParams = ['access_token='+map.access_token, 'callback=callback'];
             var query = queryParam.join("&");
             var url = parh + query;
             openImplict(url);
  		 }
  	 }
  	 
  </script>
</html>
